]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell/camera-monitor: Tweak indicator disable timeout
authorrobert.mader@collabora.com <robert.mader@collabora.com>
Sat, 29 Jul 2023 16:11:14 +0000 (19:11 +0300)
committerMarge Bot <marge-bot@gnome.org>
Sun, 30 Jul 2023 11:24:35 +0000 (11:24 +0000)
We currently consider idle nodes as in use to avoid too fast state
changes and thus flickering of the indicator icon. However, the current
idle timeout is rather long and arguably confusing for users.

Thus switch to only consider running nodes as in use, but delay
disabling of the indicator by 500ms.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2854>

src/shell-camera-monitor.c

index 34bf2ee1002cd4be3e2e392291ed0b51245bffa4..1b98b7dc88e88010c9a7a40cd1c8c65f521c0d46 100644 (file)
@@ -29,6 +29,7 @@
 #endif
 
 #define RECONNECT_DELAY_MS 5000
+#define DISABLE_DELAY_MS 500
 
 enum {
   PROP_0,
@@ -46,6 +47,7 @@ struct _ShellCameraMonitor {
 #ifdef HAVE_PIPEWIRE
   GPtrArray *node_list;
   guint reconnect_id;
+  guint delayed_disable_id;
 
   GSource *pipewire_source;
   struct pw_context *context;
@@ -76,6 +78,16 @@ typedef struct _MetaPipeWireSource
 static gboolean shell_camera_monitor_connect_core (ShellCameraMonitor *monitor);
 static void shell_camera_monitor_disconnect_core (ShellCameraMonitor *monitor);
 
+static void
+delayed_disable_state (gpointer data)
+{
+  ShellCameraMonitor *monitor = SHELL_CAMERA_MONITOR (data);
+
+  monitor->cameras_in_use = FALSE;
+  g_object_notify_by_pspec (G_OBJECT (monitor),
+                            obj_props[PROP_CAMERAS_IN_USE]);
+}
+
 static void
 shell_camera_monitor_update_state (ShellCameraMonitor *monitor)
 {
@@ -97,12 +109,21 @@ shell_camera_monitor_update_state (ShellCameraMonitor *monitor)
         }
     }
 
-  if (new_cameras_in_use != monitor->cameras_in_use)
+  if (new_cameras_in_use)
+    g_clear_handle_id (&monitor->delayed_disable_id, g_source_remove);
+
+  if (new_cameras_in_use && !monitor->cameras_in_use)
     {
       monitor->cameras_in_use = new_cameras_in_use;
       g_object_notify_by_pspec (G_OBJECT (monitor),
                                 obj_props[PROP_CAMERAS_IN_USE]);
     }
+  else if (!new_cameras_in_use && monitor->cameras_in_use &&
+           monitor->delayed_disable_id == 0)
+    {
+      monitor->delayed_disable_id =
+        g_timeout_add_once (DISABLE_DELAY_MS, delayed_disable_state, monitor);
+    }
 }
 
 static void
@@ -125,8 +146,7 @@ node_event_info (void                      *data,
 {
   Node *node = data;
 
-  node->running = (info->state == PW_NODE_STATE_RUNNING ||
-                   info->state == PW_NODE_STATE_IDLE);
+  node->running = (info->state == PW_NODE_STATE_RUNNING);
 
   shell_camera_monitor_update_state (node->monitor);
 }
@@ -275,6 +295,7 @@ static void
 shell_camera_monitor_disconnect_core (ShellCameraMonitor *monitor)
 {
   g_ptr_array_set_size (monitor->node_list, 0);
+  g_clear_handle_id (&monitor->delayed_disable_id, g_source_remove);
 
   g_clear_pointer ((struct pw_proxy**) &monitor->registry, pw_proxy_destroy);
   spa_hook_remove (&monitor->registry_listener);